<template>
  <div>
     <login-head></login-head>
     <div class="container">
       <div class="picture">
          <img src="./assets/img/logo.png" alt="">
       </div>
       <van-form>
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 30px;">
          <van-button round block type="info" @click="login" color="#884e22">
            登 陆
          </van-button>
        </div>
       </van-form>
     </div>
  </div>
</template>

<script>
import LoginHead from './components/LoginHead'
export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login () {
      // 设置定时器模拟请求数据库
      setTimeout(() => {
        // 这里需要注意要使用箭头函数
        const token = 'dsgtdudidsabxmdsgf'
        localStorage.setItem('access_token', token)
        // 回到重定向之前的路由
        console.log(this.$route.params.from)
        if (this.$route.params.from) {
          this.$router.push(this.$route.params.from)
        } else {
          this.$router.push('/home')
        }
      }, 1000)
    }
  },
  components: {
    LoginHead
  }
}
</script>

<style lang="scss" scoped>
.picture{
  height: 120px;
  text-align: center;
  margin-top: 30px;
  img{
    width: 150px;
  }
}
.van-button{
  margin: 30px 0;
}
</style>
